#!/use/bin/python3

import os

# 1、读取数据
with open("students.txt",mode="r",encoding="UTF-8") as file:
    students = [line.rstrip() for line in file.readlines()]

# 获取班级列表
clazzs = set([stu.split(",")[-1] for stu in students])

# 循环创建目录
for clazz in clazzs:
    # 创建目录
    os.mkdir(clazz)
    # 保存数据到文件
    with open(f"{clazz}/data.txt",mode="w",encoding="UTF-8") as file:
        for stu in students:
            if clazz == stu.split(",")[-1]:
                file.write(f"{stu}\n")